package com.cy.myblog.action.user;

import com.cy.myblog.action.BaseAction;
import com.cy.myblog.pageModel.Json;
import com.cy.myblog.pageModel.User;
import com.cy.myblog.service.UserServiceI;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * Created by Administrator on 2015/8/2.
 */
@Controller
@Scope("prototype")
@ParentPackage("basePackage")
@Namespace("/user")
@Action(value = "userManageAction")
public class UserManageAction extends BaseAction implements ModelDriven<User>
{
    private static final long serialVersionUID = -7297703347775065119L;

    private User user = new User();
    @Override
    public User getModel() {
        return user;
    }

    private UserServiceI userService;

    @Autowired
    public void setUserService(UserServiceI userService) {
        this.userService = userService;
    }

    public void load(){
        super.writeJson(userService.findByPage(user));
    }

    public void remove(){
        Json json = new Json();
        userService.delete(user);
        json.setSuccess(true);
        json.setMsg("删除成功!");
        super.writeJson(json);
    }
}
